package main.visual;

import java.util.ArrayList;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import Preferences.GestioneLocali;
import bean.Locale;

@ManagedBean(name="locali")
@SessionScoped
public class VisualizzaLocali {
	private ArrayList<Locale> locali;
	private Locale selected;

	@ManagedProperty(value="#{gestioneLocali}")
	private GestioneLocali gestioneLocali;
	public void setGestioneLocali(GestioneLocali gs) {
		this.gestioneLocali = gs;
	}

	@PostConstruct
	public void init(){
		locali = gestioneLocali.getLocali();
	}
	
	public String select (Locale l)
	{
		setSelected(l);
		return "ok";
	}

	public boolean isSelected(Locale locale) {
		return selected.equals(locale);
	}

	////////////////////////////////////////////////////////////////////
	//Getters and setters
	public Locale getSelected() {
		return selected;
	}
	public void setSelected(Locale selected) {
		if (this.selected != null)
			this.selected.setSelected(false);
		selected.setSelected(true);
		this.selected = selected;
	}
	////////////////////////////////////////////////////////////////////
}
